package com.twm.client;

import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;

public class CuratorClient {

    public static String path = "/netty-provider";

    public static CuratorFramework curatorClient;

    public static CuratorFramework getCuratorClient(){
        if (curatorClient == null){
            RetryPolicy exponentialBackoffRetry = new ExponentialBackoffRetry(1000, 3);
            //使用fluent变成风格
            curatorClient = CuratorFrameworkFactory.builder()
                    .connectString("127.0.0.1:2181")
                    .sessionTimeoutMs(5000)
                    .connectionTimeoutMs(3000)
                    .retryPolicy(exponentialBackoffRetry)
                    .namespace("base")  //独立的命名空间
                    .build();
            curatorClient.start();
        }
        return curatorClient;
    }

}
